<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>
	<body>
		<button class="remove-btn">删除元素</button>
		<button class="copy-btn">克隆</button>

		<div class="box">
			<h2>我是标题</h2>
			<p>我是文本, 哈哈哈</p>
		</div>

		<script>
			var boxEl = document.querySelector('.box')
			var removeBtnEl = document.querySelector('.remove-btn')
			var copyBtnEl = document.querySelector('.copy-btn')

			removeBtnEl.onclick = function () {
				boxEl.remove()
			}

			copyBtnEl.onclick = function () {
				// cloneNode(true): 是否深度拷贝
				var newNode = boxEl.cloneNode(true)

				boxEl.append(newNode)
			}
		</script>
	</body>
</html>
